<template>
	<view>
		<van-collapse :value="showReview" accordion @change="onChange">
			<van-collapse-item v-for="(item,index) in list" :key="item.orderId">
				<template #title>
					<view style="font-size: 30rpx; display: flex;align-items:center;justify-content: space-between;">
						<view style="font-weight: 600;" v-text="item.shopName+'>'" @click="onClickShop(item.shopId)"></view>
						<van-rate :value="item.score" readonly />
					</view>
				</template>
				<view>
					<view class="flexView">
						<view style="color: #3F536E;font-size: 30rpx;" @click="onClickInfo(item.orderId)">
							订单详情
						</view>
						<view style="display: flex;width: 20%;align-items: center;justify-content: space-between;">
							<view style="color: #DD524D;" @click="onClickDelete(item.orderId)">删除</view>
						</view>
					</view>
					<view class="text" v-text="item.text">
					</view>
					<image v-for="(iitem,iindex) in item.image" :key="index" :src="iitem" mode="aspectFit" class="reviewImage" />
					<view style="margin-top: 10rpx;" v-text="getTime(item.time)"></view>
				</view>
			</van-collapse-item>
		</van-collapse>
		<view class="safeView"></view>
	</view>
</template>

<script>
	export default {
		data(){
			return {
				showReview:-1,
				list:[]
			}
		},
		onLoad(){
			const that=this;
			that.getReview();
		},
		methods:{
			//get
			getReview(){
				const that=this;
				wx.showLoading();
				wx.request({
					method:'POST',
					url:that.myConfig.apiUrl+'/getReview.php',
					data:{
						openId:that.myConfig.openId
					},
					success:function(res){
						wx.hideLoading();
						console.log('getReview',res);
						that.list=res.data.review;
					},
					fail:function(){
						wx.hideLoading();
						that.myConfig.err();
					}
				});
			},
			//点击店铺
			onClickShop(shopId){
				uni.navigateTo({
					url:'/pages/shop/shop?'+'shopId='+shopId
				});
			},
			//转化事件
			getTime(time){
				const that=this;
				return that.myConfig.tansf(time);
			},
			//切换展示的评论
			onChange(value){
				const that=this;
				if(that.showReview!=value.detail)
					that.showReview=value.detail;
				else
					that.showReview=-1;
			},
			//点击删除
			onClickDelete(orderId){
				const that=this;
				uni.showModal({
					title:'林大干饭人',
					content:'你确认要删除吗',
					cancelText:'点错了',
					confirmText:'确认删除',
					success:function(mod){
						if(mod.confirm){
							wx.showLoading();
							wx.request({
								url:that.myConfig.apiUrl+'/deleteReview.php',
								method:'POST',
								data:{
									openId:that.myConfig.openId,
									orderId:orderId
								},
								success:function(res){
									wx.hideLoading();
									console.log('deleteReview',res);
									uni.showToast({
										title:'删除成功',
										icon:'none',
										duration:1200
									});
									that.getReview();
								},
								fail:function(){
									wx.hideLoading();
									that.myConfig.err();
								}
							});
						}
					}
				});
			},
			//显示订单详情
			onClickInfo(orderId){
				uni.switchTab({
					url:'../order/order?orderId='+orderId
				});
			}
		}
	}
</script>

<style scoped>
	.text{
		font-size: 30rpx;
	}
	.reviewImage{
		width: 220rpx;
		height: 220rpx;
		margin: 5rpx;
	}
	.flexView{
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-size: 25rpx;
		font-weight: 600;
	}
</style>
